<?php require_once 'model/page_db.php';?>
<?php
if (isset($_POST["submit"])){
    $pages = getDataPage("SELECT * from pages",
                          (int) $_POST["min"],
                          (int) $_POST["max"],
                          $_POST["key"],
                          $_POST["app"],
                          (int)$_POST["company"],
                          10);
}
else{
    $pages = getDataPage("SELECT * from pages",
                          null,
                          null,
                          null,
                          null,
                          null,
                          10);
}
$companys=  getDataCompany("SELECT * FROM companies");
$apps=  getDataApp("SELECT * FROM apps");
?>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link href="public/css/page.css" type="text/css" rel="stylesheet">
<div id="khung">
    <form method="post">
        <div id="control">
            <input type="tex" name="min" placeholder="Min Fans"/>
            <input type="tex" name="max" placeholder="Max Fans"/>
            <input type="tex" name="key" placeholder="Key"/>
            <select name="company">
                <option value="0">--- Company -----</option>
                <?php foreach ($companys as $company) : ?>
                    <option value="<?php echo $company["id"]; ?>"><?php echo $company["name"]; ?></option>
                <?php endforeach; ?>
            </select>
             <select name="app">
                 <option value="0">--- Apps -----</option>
                <?php foreach ($apps as $app) : ?>
                    <option value="<?php echo $app["id"]; ?>"><?php echo $app["name"]; ?></option>
                <?php endforeach; ?>
            </select>
            <input name="submit" value="Search" type="submit">
        </div>
    </form>
    <div class="item-head" id="head">
    <div class="img">Image</div>
    <div class="name">Name</div>
    <div class="like"> Like</div>
    <div class="talking">Talking </div>
    <div class="category">Category</div>
    <div class="country">Country</div>
    <div class="description"> Description</div>
    </div>
    <?php if(!empty($pages)){?>
    <?php foreach ($pages as $page) :?>
    <div class="item">
    <div class="img"><img src="<?php echo $page["picture"];?>" align="left"/></div>
    <div class="name"><?php echo $page["name"];?></div>
    <div class="like"> <?php echo $page["likes"]; ?></div>
    <div class="talking"> <?php echo $page["talking_about_count"]; ?> </div>
    <div class="category"> <?php echo $page["category"]; ?> </div>
    <div class="country"> <?php echo $page["country"]; ?> </div>
    <div class="description"> <?php echo $page["description"], 10 ?> </div>
    </div>
    <?php endforeach;?>
    <?php } else {?>
    <div class="err" style="clear: both; text-align: center;">
        <center>
    <?php echo "NOT SEARCH";?>
        </center>
    </div>
    <?php }?>
    <div style="clear: both" id="phantrang">&nbsp;</div>
</div>